﻿
<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>持名法州主页</title>


    <link rel="stylesheet" href="${pageContext.request.contextPath}/themes/icon.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/themes/default/easyui.css">


 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min1.3.5.js"></script>
 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min1.3.5.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>


<script type="text/javascript">
	<!--菜单处理-->
    $(function () {
        $("#gridtable").datagrid({
            title:'图片展示列表',
            url:'${pageContext.request.contextPath}/Article/showArticle',
            pagination:'true',
            fit:'true',
            columns:[[
                //增加复选框；
                {checkbox:true},
                //展示图片信息；
                {title:'文章ID值',field:'articleId'},
                {title:'文章名称',field:'articleName'},
                {title:'文章图片',field:'articleImage',
                    formatter:function (value,data,index) {
                        return"<img src='${pageContext.request.contextPath}"+value+"' width='100px'>"
                    }
                },
                {title:'文章简介',field:'articleContent'},
                {title:'所属上师的ID值',field:'guruId'},
                {title:'文章发布时间',field:'articleDate'},
            ]],
            onDblClickRow:function (Index,data) {
                $("#articleupdate").dialog("open");
                $("#updateId").val(data.articleId);
                $("#updatename").val(data.articleName);
                $("#updateimage").val(data.articleImage);
                $("#updatecontent").val(data.articleContent);
                $("#updateguruid").val(data.guruId);
                $("#updatedate").val(data.articleDate);
            },
            toolbar:"#toolsbut",
        })
        $("#articleupdate").dialog({
            title:'批量添加论面板',
            width:'400',
            height:'400',
            buttons:'#addBut',
            closed:'true'
        })
        $("#articleadd").dialog({
            title:'批量添加论面板',
            width:'400',
            height:'400',
            buttons:'#addBut',
            closed:'true'
        })
        $('#ss').searchbox({
            searcher:function(value,name){
                alert(value),
                $.ajax({
                    url:"${pageContext.request.contextPath}/Lucence/queryArticle",
                    data:"keyWord="+value,
                    success:function (data) {
                        alert(data)
                        $("#gridtable").datagrid("loadData",data)
                    }
                })

            },
            prompt:'请输入您要查询的值'
        });

    })

    function addbord() {
        $("#articleadd").dialog("open")
    }
    function updateMess() {
        $("#updateform").form("submit",{
            url:"${pageContext.request.contextPath}/Article/updateArticle",
            onSubmit:function () {
                var inf = $(this).form("validate");
                return inf
            }
        });
        $("#gridtable").datagrid("reload")
        $("#articleupdate").dialog("close");
    }

    function dele() {
        //获取标签元素加控件名称，调用相应的方法，获取所有的选中的id值；
        var AllIds=$("#gridtable").datagrid("getSelections")
        //判断所获中的id值是否为空进行判断；
        if(AllIds.length==0){
            alert("请选择中要删除的数据！！")
        }
        //创建新的数组；
        var ids=new Array(AllIds.length);
        alert(ids)
        //在遍历的时候进行赋值给新建的数组，然后进行传递给后台进行操作数据库；
        for(var i=0;i<ids.length;i++){
            ids[i]=AllIds[i].articleId;
        }
        alert(ids);
        //发送ajax请求
        $.ajax({
            url:"${pageContext.request.contextPath}/Article/deleteMany",
            data:"ids="+ids,
        })
        $("#gridtable").datagrid("reload")
    }

    function addOne() {
        /*获取标签元素.控件名称，调用sumbit方法，其参数为对象类型，用花括号，请求路径，提交前的验证回掉函数，根据返回值
        来确定是否提交，操作完数据的回掉函数，用来反映操作数据库的操作结果*/
        $("#addform").form("submit",{
            url:"${pageContext.request.contextPath}/Article/addArticle",
            onSubmit:function () {
                var inf=$(this).form("validate");
                return inf
            },
        })
        $("#gridtable").datagrid("reload");
        $("#banneradd").dialog("close");
    }


</script>

</head>
<body>
<table id="gridtable">
</table>


<div id="toolsbut">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'"></a>
    <shiro:hasRole name="admin">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="dele()">批量删除</a>
    </shiro:hasRole>
    <shiro:hasRole name="superadmin">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addbord()">添加</a>
    </shiro:hasRole>

   <%--运用lucence得查询框；--%>
    <input id="ss">
</div>

<div id="articleupdate">
    <form id="updateform" method="post">
        <input type="hidden" id="updateId" name="articleId">
        文章的名称：<input id="updatename" name="articleName"><br/>
        文章的图片：<input id="updateimage" name="articleImage"><br/>
        文章简介：<input id="updatecontent" name="articleContent"><br/>
        所属上师的ID值：<input id="updateguruid" name="guruId"><br/>
        文章上传的时间：<input id="updatedate" name="articleDate"><br/>
        <input type="button" onclick="updateMess()" value="修改">
    </form>
</div>

<div id="articleadd">
    <form id="addform" method="post">
        文章的名称：<input name="articleName"><br/>
        文章的图片：<input  name="articleImage"><br/>
        文章简介：<input  name="articleContent"><br/>
        所属上师的ID值：<input  name="guruId"><br/>
        文章上传的时间：<input  name="articleDate"><br/>
        <input type="button" onclick="addOne()" value="添加">
    </form>
</div>



</body>
</html>